﻿$(document).ready(function () {
    var slider = $('#home-books-slider');

    // calculate the width for the slider
    slider.width(125 * $('.home-book').length);
    $('.scroll-button').click(function () {
        var $this = $(this);
        if (slider.is(':animated')) return;

        if ($this.hasClass('right') && (slider.width() + slider.position().left) > $('.home-books-slider-container').width()) {
            var moveWidth = slider.width() + slider.position().left - $('.home-books-slider-container').width();
            if (moveWidth > 125) moveWidth = 125;
            slider.animate({ "left": "-=" + moveWidth + "px" }, "normal");
        } else if ($this.hasClass('left') && slider.position().left < 0) {
            var moveWidth = -slider.position().left;
            if (moveWidth > 125) moveWidth = 125;
            slider.animate({ "left": "+=" + moveWidth + "px" }, "normal");
        }
    });
});
